package dao

import (
	"chat/inits"
	"chat/model"
	"chat/until"
)

func GetUser(username, password string) (result *model.User, err error) {
	if err = inits.DB.Where("username=? and password=?", username, until.Md5(password)).Find(&result).Error; err != nil {
		return nil, err
	}
	return result, nil
}
func CreateUser(username, password string) (err error) {
	result := &model.User{
		Username: username,
		Password: until.Md5(password),
	}
	if err = inits.DB.Create(&result).Error; err != nil {
		return err
	}
	return nil
}
func ListUser() (result []*model.User, err error) {
	if err = inits.DB.Find(&result).Error; err != nil {
		return nil, err
	}
	return result, nil
}
